//
//  YCInterviewCommitSucceedView.m
//  YCSchool
//
//  Created by gmall on 16/5/5.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  报名提交成功

#import "YCInterviewCommitSucceedView.h"

@interface YCInterviewCommitSucceedView ()
/** 提交成功背景  */
@property (nonatomic, weak) UIView *bgView;
/** 提交成功界面完成按钮的回调block  */
@property (nonatomic, copy) completeBlock completeBlock;
@end

@implementation YCInterviewCommitSucceedView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self makeView];
    }
    return self;
}


- (void)makeView
{
    self.backgroundColor = [UIColor colorWithWhite:0.2 alpha:1];
    self.yc_size = CGSizeMake(kScreenWidth, kScreenWidth);
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    self.bgView = bgView;
    
    UILabel *commitsucceedLabel = [[UILabel alloc] init];
    commitsucceedLabel.text = @"提交成功";
    commitsucceedLabel.font = [UIFont systemFontOfSize:15];
    [self addSubview:commitsucceedLabel];

    UILabel *infoLabel = [[UILabel alloc] init];
    infoLabel.text = @"我驾校会为您安排模拟考试时间";
    infoLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:infoLabel];
    
    UIButton *completeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    completeBtn.backgroundColor = [UIColor yc_colorWithUInt:0x5270a7];
    completeBtn.layer.cornerRadius = 5;
    completeBtn.layer.masksToBounds = YES;
    [completeBtn setTitle:@"完成" forState:UIControlStateNormal];
    [completeBtn addTarget:self action:@selector(touchUpInsideCompleteButton) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:completeBtn];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(heightFromIphone6Height(216)+kScreenHeight);
        make.left.equalTo(self).offset(50);
        make.right.equalTo(self).offset(-50);
    }];
    
    [commitsucceedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView).offset(heightFromIphone6Height(36));
        make.centerX.equalTo(bgView);
    }];
    
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(commitsucceedLabel.mas_bottom).offset(heightFromIphone6Height(35));
        make.centerX.equalTo(bgView);
    }];
    
    [completeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(infoLabel.mas_bottom).offset(heightFromIphone6Height(45));
        make.centerX.equalTo(bgView);
        make.width.equalTo(@103);
        make.height.equalTo(@34);
    }];
    
    [bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(completeBtn.mas_bottom).offset(heightFromIphone6Height(28));
    }];
    
    [self layoutIfNeeded];
}


// 弹出提交成功视图
- (void)showSucceedMessge:(NSString *)msg inView:(UIView *)view completeBlock:(completeBlock)completeBlock
{
    self.completeBlock = completeBlock;
    self.frame = view.window.bounds;
    [view.window addSubview:self];
    [UIView animateWithDuration:0.25 animations:^{
        [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(heightFromIphone6Height(216));
            [self layoutIfNeeded];
        }];
    }];
}
// 完成
- (void)touchUpInsideCompleteButton
{
    !self.completeBlock ?:self.completeBlock();
    [UIView animateWithDuration:0.25 animations:^{
        [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(heightFromIphone6Height(216)+kScreenHeight);
        }];
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}

@end
